package com.sms.graduate.utils;

import com.sms.graduate.entity.SmsClasscourse;
import com.sms.graduate.service.SmsClasscourseService;
import com.sms.graduate.service.SmsDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;


@Component
public class DataTools {

    public static SmsDictionaryService SMSDICTIONARYSERVICE;
    public static SmsClasscourseService SMSCLASSCOURSESERVICE;

    @Autowired
    SmsDictionaryService smsDictionaryService;

    @Autowired
    SmsClasscourseService smsClasscourseService;

    @PostConstruct
    public void init(){
        SMSDICTIONARYSERVICE =smsDictionaryService;
        SMSCLASSCOURSESERVICE=smsClasscourseService;
    }

  /* private SmsDictionaryService smsDictionaryService;

    public void setSmsDictionaryService(SmsDictionaryService smsDictionaryService) {
        this.smsDictionaryService = smsDictionaryService;
    }*/
    public static HashMap<Integer,List<SmsClasscourse>> allCourse(String courseClass){
        HashMap<Integer,List<SmsClasscourse>> hashMap = new HashMap<>();
        hashMap.put(1,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.a));
        hashMap.put(2,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.b));
        hashMap.put(3,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.c));
        hashMap.put(4,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.d));
        hashMap.put(5,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.e));
        hashMap.put(6,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.f));
        hashMap.put(7,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.g));
        hashMap.put(8,SMSCLASSCOURSESERVICE.courseByClass(courseClass, ConstantUtils.h));
        return hashMap;
    }

    public static String classByUserCode(String userCode){
        String substring = userCode.substring(0, 4);
        return substring+"级";
    }

    public static String collegeByUserCode(String userCode){
        String substring = userCode.substring(4, 6);
        return SMSDICTIONARYSERVICE.selectClass(substring, 1);
    }

    public static String majorByUserCode(String userCode){
        String substring = userCode.substring(6, 8);
        return SMSDICTIONARYSERVICE.selectClass(substring, 2);
    }
    public static  String gradeByUserCode(String userCode){
        String substring = userCode.substring(8, 10);
        return substring+"班";
    }

    public static String gradeAndMajor(String userCode){
        return  majorByUserCode(userCode)+gradeByUserCode(userCode);
    }


}
